package cn.jolyoulu.common.redis.config;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;

import java.time.Duration;

/**
 * @Author: JolyouLu
 * @Date: 2023/12/31 17:01
 * @Description
 */
@Configuration
@ConfigurationProperties(value = "redis-module-config.basic")
public class RedisBasicProperties {

    /**
     * 连接分区
     */
    private int database = 0;
    /**
     * 连接地址
     */
    private String host;
    /**
     * 连接密码配置
     */
    private String password;
    /**
     * 连接端口
     */
    private int port = 6379;
    /**
     * 执行指令超时时间
     */
    private Duration timeout = Duration.ofMillis(3000);
    /**
     * 连接池配置
     */
    private Pool pool;

    public int getDatabase() {
        return database;
    }

    public void setDatabase(int database) {
        this.database = database;
    }

    public String getHost() {
        return host;
    }

    public void setHost(String host) {
        this.host = host;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public int getPort() {
        return port;
    }

    public void setPort(int port) {
        this.port = port;
    }

    public Duration getTimeout() {
        return timeout;
    }

    public void setTimeout(Duration timeout) {
        this.timeout = timeout;
    }

    public Pool getPool() {
        return pool;
    }

    public void setPool(Pool pool) {
        this.pool = pool;
    }

    public static class Pool {
        /**
         * 最大空闲连接数量
         */
        private int maxIdle = 8;
        /**
         * 最小空闲连接数量
         */
        private int minIdle = 0;
        /**
         * 最大活跃线程数量
         */
        private int maxActive = 8;
        /**
         * 但线程池耗尽时，新的请求最大等待时间
         */
        private Duration maxWait = Duration.ofMillis(-1);

        public int getMaxIdle() {
            return maxIdle;
        }

        public void setMaxIdle(int maxIdle) {
            this.maxIdle = maxIdle;
        }

        public int getMinIdle() {
            return minIdle;
        }

        public void setMinIdle(int minIdle) {
            this.minIdle = minIdle;
        }

        public int getMaxActive() {
            return maxActive;
        }

        public void setMaxActive(int maxActive) {
            this.maxActive = maxActive;
        }

        public Duration getMaxWait() {
            return maxWait;
        }

        public void setMaxWait(Duration maxWait) {
            this.maxWait = maxWait;
        }
    }
}
